package dao;

import mappers.RoleMapper;
import model.Role;
import org.apache.ibatis.session.SqlSession;
import utils.MyBatisUtil;

public class RoleDAO implements RoleMapper {

    @Override
    public void insertRole(Role role) {
        SqlSession sqlSession = MyBatisUtil.getSqlSessionFactory().openSession();
        try {
            RoleMapper roleMapper = sqlSession.getMapper(RoleMapper.class);
            roleMapper.insertRole(role);
            sqlSession.commit();
        }
        finally {
            sqlSession.close();
        }
    }

    @Override
    public Role getRoleById(int id) {
        SqlSession sqlSession = MyBatisUtil.getSqlSessionFactory().openSession();
        try {
            RoleMapper roleMapper = sqlSession.getMapper(RoleMapper.class);
            Role role = roleMapper.getRoleById(id);
            return role;
        }
        finally {
            sqlSession.close();
        }
    }
}
